package com.cn.wanxi.service.impl;

import com.cn.wanxi.dao.DesignerDao;
import com.cn.wanxi.dao.ProductDao;
import com.cn.wanxi.dao.UserDao;
import com.cn.wanxi.dao.impl.DesignerImpl;
import com.cn.wanxi.dao.impl.ProductImpl;
import com.cn.wanxi.dao.impl.UserImpl;
import com.cn.wanxi.model.DesignerModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.service.DesignerService;

import java.util.List;

public class DesignerServiceImpl implements DesignerService {
    @Override
    public ResultModel findAll(DesignerModel designerModel) {
        ResultModel resultModel = new ResultModel();
        DesignerDao designerDao = new DesignerImpl();
        List<DesignerModel> list = designerDao.findAll(designerModel);
        resultModel.setData(list);
        return resultModel;
    }

    @Override
    public ResultModel add(DesignerModel designerModel) {
        DesignerDao designerDao = new DesignerImpl();
        int count=designerDao.add(designerModel);
        return new ResultModel("",0,count,null);
    }

    @Override
    public ResultModel findById(DesignerModel designerModel) {
        ResultModel resultModel = new ResultModel();
        DesignerDao designerDao = new DesignerImpl();
        DesignerModel model = designerDao.findById(designerModel);
        resultModel.setData(model);
        return resultModel;
    }

    @Override
    public ResultModel update(DesignerModel designerModel) {
        ResultModel resultModel = new ResultModel();
        DesignerDao designerDao = new DesignerImpl();
        int count = designerDao.update(designerModel);
        if (count > 0) {
            resultModel.setMsg("success");
        } else {
            resultModel.setMsg("error");
        }
        return resultModel;
    }

    @Override
    public ResultModel delete(DesignerModel designerModel) {
        ResultModel resultModel = new ResultModel();
        DesignerDao designerDao = new DesignerImpl();
        int count = designerDao.delete(designerModel);
        if (count > 0) {
            resultModel.setMsg("success");
        } else {
            resultModel.setMsg("error");
        }
        return resultModel;
    }

    @Override
    public ResultModel getCount(DesignerModel designerModel) {
        ResultModel resultModel = new ResultModel();
        DesignerDao designerDao = new DesignerImpl();
        int count = designerDao.getCount(designerModel);
        resultModel.setCount(count);
        return resultModel;
    }
}
